package com.example.guiguihomemedical.controller;

import com.example.guiguihomemedical.common.Result;
import com.example.guiguihomemedical.entity.Examination;
import com.example.guiguihomemedical.entity.Signing;
import com.example.guiguihomemedical.entity.dto.*;
import com.example.guiguihomemedical.service.ExaminaionService;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import java.text.ParseException;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("examination")
public class ExaminationController {
    @Autowired
    private ExaminaionService examinaionService;

    @PostMapping("add")
    public Result addExamination(MultipartHttpServletRequest request) throws ParseException {

        String examinationAddJson = request.getParameter("examinationAdd");
        ExaminationAdd examinationAdd = new Gson().fromJson(examinationAddJson, ExaminationAdd.class);
        MultipartFile uploadFile = request.getFile("file");
        examinaionService.addExaminaion(examinationAdd, uploadFile);
        return Result.success();
    }
    @PostMapping("postExaminationTable")
    public Result postExaminationTable(MultipartHttpServletRequest request)throws ParseException{
        String examinationTableAddJson = request.getParameter("examinationInfo");
        ExaminationTableAdd examinationTableAdd = new Gson().fromJson(examinationTableAddJson, ExaminationTableAdd.class);
        MultipartFile uploadFile = request.getFile("file");
        examinaionService.postExaminationTable(examinationTableAdd, uploadFile);
        return Result.success();
    }

    @GetMapping("signinglist")
    public Result getExaminationSigningList() {
        List<ExaminationSigning> examinationSignings = examinaionService.getExaminationSigningList();
        return Result.success(examinationSignings);
    }

    @PostMapping("recordlist")
    public Result getExaminationRecordList(@RequestBody ExaminationRecordSearch examinationRecordSearch) {
        List<ExaminationRecord> examinationRecords = examinaionService.getExaminationRecordList(examinationRecordSearch);
        return Result.success(examinationRecords);
    }

    @GetMapping("signingsearch/{idcardname}")
    public Result getExaminationSigningSearch(@PathVariable String idcardname) {
        List<ExaminationSigning> examinationSignings = examinaionService.getExaminationSigningSearch(idcardname);
        return Result.success(examinationSignings);

    }

    @GetMapping("examinationdetail/{examinationId}")
    public Result getExaminationDetailByIdcard(@PathVariable Integer examinationId) {
        Examination examination = examinaionService.getExaminationDetailByIdcard(examinationId);
        return Result.success(examination);
    }

 @PostMapping("examinaionmodify")
    public Result modifyExaminationById(@RequestBody Examination  examination){
     examinaionService.modifyExaminationById(examination);
     return Result.success();
 }
  @GetMapping("getaddstatus/{idcard}")
    public Result GetAddStatus(@PathVariable String idcard){
        String status=examinaionService.GetAddStatus(idcard);
        return Result.success(status);
  }

}
